package com.css.zfzx.sjcj.modules.drill.basedivision.repository;


import com.css.zfzx.sjcj.modules.drill.basedivision.repository.entity.DivisionsEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BaseDivisionRepository extends JpaRepository<DivisionsEntity, String> {


    List<DivisionsEntity> findByIsValid(String isValid);

    @Query(
            nativeQuery = true,
            value = "select * from org_division where is_valid = '1' and division_name = :divisionName"
    )
    List<DivisionsEntity> findValidDivisionCodeByName(@Param("divisionName") String divisionName);

    @Query(
            nativeQuery = true,
            value = "select all_parent_id from org_division where division_id = ?1 "
    )
    String findAllParentIdByDivisionId(String divisionId);

    @Query(
            nativeQuery = true,
            value = "select division_name from org_division where division_id in ?1 order by level "
    )
    List<String> findDivisionNamesByDivisionId(String[] ids);


}
